<!DOCTYPE html><html lang="zh-tw"><head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>&#x5BF9;&#x8C61;&#x7684;&#x6269;&#x5C55; | ECMAScript 6&#x5165;&#x95E8;</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.4.3">
        <meta name="author" content="&#x5927;&#x9F3B;&#x5B50;">
        
        <meta name="HandheldFriendly" content="true">
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="https://wohugb.gitbooks.io/ecmascript-6/content/gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="https://gstatic.gitbook.com/images/b1c4c86ca817a71628d2debe73be9a64.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="static/css/style.css">
    
        
        <link rel="stylesheet" href="static/css/website.css">
        
    
    

        
    
    
    <link rel="next" href="function.html">
    
    
    <link rel="prev" href="array.html">
    

        
    
<style>
    .book .book-summary .book-search,
    .book .book-summary ul.summary {
        position: relative;
        top: auto;
        left: auto;
        right: auto;
        bottom: auto;
    }
    .book-summary {
        display: -webkit-box;
        display: -moz-box;
        display: -ms-flexbox;
        display: -webkit-flex;
        display: flex;
        flex-direction: column;
        -webkit-box-orient: vertical;
        -webkit-box-direction: normal;
        overflow-y: auto;
    }
    .book-summary > nav {
        flex: 1 1 auto;
        overflow-y: auto;
        overflow-y: overlay;
    }
    .gl-wrapper {
        margin: 0;
        display: block;
        padding: 0;
        position: relative;
        line-height: 15px;
        background: #fafafa;
    }
    .gl-wrapper:before {
        background: -webkit-linear-gradient(to bottom, rgba(250,250,250,0) 0%, #fafafa 100%);
        background: -moz-linear-gradient(to bottom, rgba(250,250,250,0) 0%, #fafafa 100%);
        top: -24px;
        width: 100%;
        height: 24px;
        content: "";
        display: block;
        position: absolute;
        background: linear-gradient(to bottom, rgba(250,250,250,0) 0%, #fafafa 100%);
    }
    .book.color-theme-1 .gl-wrapper {
        background: #121212;
    }
    .book.color-theme-1 .gl-wrapper:before {
        background: -webkit-linear-gradient(to bottom, rgba(18,18,18,0) 0%, #121212 100%);
        background: -moz-linear-gradient(to bottom, rgba(18,18,18,0) 0%, #121212 100%);
        background: linear-gradient(to bottom, rgba(18,18,18,0) 0%, #121212 100%);
    }
    .book.color-theme-2 .gl-wrapper {
        background: #2e3243;
    }
    .book.color-theme-2 .gl-wrapper:before {
        background: -webkit-linear-gradient(to bottom, rgba(46,50,67,0) 0%, #2e3243 100%);
        background: -moz-linear-gradient(to bottom, rgba(46,50,67,0) 0%, #2e3243 100%);
        background: linear-gradient(to bottom, rgba(46,50,67,0) 0%, #2e3243 100%);
    }
    .gl-wrapper .gitbook-link {
        display: -webkit-box;
        display: -moz-box;
        display: -ms-flexbox;
        display: -webkit-flex;
        color: #9DAAB6;
        margin: 16px;
        display: flex;
        padding: 0;
        align-items: center;
        margin-left: 32px;
        padding-top: 8px;
        padding-left: 16px;
        border-radius: 3px;
        padding-right: 16px;
        padding-bottom: 8px;
        text-decoration: none;
        background-color: #E6ECF1;
        -webkit-box-align: center;
    }
    .gl-wrapper .tm-logo {
        margin: 0;
        display: block;
        padding: 0;
        font-size: 40px;
    }
    .gl-wrapper .tm-content {
        flex: 1;
        margin: 0;
        display: block;
        padding: 0;
        padding-left: 16px;
    }
    .gl-wrapper .tm-content .container {
        margin: 0;
        display: block;
        padding: 0;
    }
    .gl-wrapper .tm-content .tm-container .tm-text {
        font-size: 12px;
        font-family: "Roboto", sans-serif;
        font-weight: 400;
        line-height: 1.625;
    }
</style></head>
    <body>
        
        
    <div class="book" data-level="7" data-basepath=".." data-revision="Sun Oct 25 2015 02:52:03 GMT+0000 (UTC)">
    

<div class="book-summary">
    <div class="book-search" role="search">
        <input type="text" placeholder="&#x8F38;&#x5165;&#x4E26;&#x641C;&#x5C0B;" class="form-control">
    </div>
    <nav role="navigation">
        <ul class="summary">
            
            
            
                
                <li>
                    <a href="javascript:;" target="blank" class="custom-link">ECMAScript 6&#x5165;&#x95E8;</a>
                </li>
            
            

            
            <li class="divider"></li>
            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="index.html">
                
                        <i class="fa fa-check"></i>
                        
                        &#x524D;&#x8A00;
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="docs/intro.html">
            
                
                    <a href="intro.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        &#x7B80;&#x4ECB;
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2" data-path="docs/let.html">
            
                
                    <a href="let.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        let&#x548C;const&#x547D;&#x4EE4;
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3" data-path="docs/destructuring.html">
            
                
                    <a href="destructuring.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        &#x53D8;&#x91CF;&#x7684;&#x89E3;&#x6784;&#x8D4B;&#x503C;
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4" data-path="docs/string.html">
            
                
                    <a href="string.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        &#x5B57;&#x7B26;&#x4E32;&#x7684;&#x6269;&#x5C55;
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5" data-path="docs/number.html">
            
                
                    <a href="number.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        &#x6570;&#x503C;&#x7684;&#x6269;&#x5C55;
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6" data-path="docs/array.html">
            
                
                    <a href="array.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        &#x6570;&#x7EC4;&#x7684;&#x6269;&#x5C55;
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="7" data-path="docs/object.html">
            
                
                    <a href="">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.</b>
                        
                        &#x5BF9;&#x8C61;&#x7684;&#x6269;&#x5C55;
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8" data-path="docs/function.html">
            
                
                    <a href="function.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.</b>
                        
                        &#x51FD;&#x6570;&#x7684;&#x6269;&#x5C55;
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9" data-path="docs/set-map.html">
            
                
                    <a href="set-map.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.</b>
                        
                        Set&#x548C;Map&#x6570;&#x636E;&#x7ED3;&#x6784;
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10" data-path="docs/iterator.html">
            
                
                    <a href="iterator.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.</b>
                        
                        Iterator&#x548C;for...of&#x5FAA;&#x73AF;
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="11" data-path="docs/generator.html">
            
                
                    <a href="generator.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>11.</b>
                        
                        Generator &#x51FD;&#x6570;
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12" data-path="docs/promise.html">
            
                
                    <a href="promise.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.</b>
                        
                        Promise&#x5BF9;&#x8C61;
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="13" data-path="docs/class.html">
            
                
                    <a href="class.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>13.</b>
                        
                        Class&#x548C;Module
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="14" data-path="docs/reference.html">
            
                
                    <a href="reference.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>14.</b>
                        
                        &#x53C2;&#x8003;&#x94FE;&#x63A5;
                    </a>
            
            
        </li>
    


            
            <li class="divider"></li>
            
            
        </ul>
    </nav>

<div class="gl-wrapper">
    <a class="gitbook-link" href="javascript:;" target="blank">
        <div class="tm-logo">
            <svg preserveaspectratio="xMidYMid meet" height="1em" width="1em" fill="currentColor" viewbox="0 0 1067 769" xmlns="http://www.w3.org/2000/svg" stroke="none" class="icon-7f6730be--text-3f89f380"><g><path d="M480.026 640.677c17.205 0 31.2 13.997 31.2 31.194s-13.995 31.193-31.2 31.193c-17.197 0-31.193-13.996-31.193-31.193 0-17.197 13.996-31.194 31.193-31.194m489.93-193.226c-17.203 0-31.2-13.998-31.2-31.195 0-17.204 13.997-31.2 31.2-31.2 17.198 0 31.194 13.996 31.194 31.2 0 17.197-13.996 31.195-31.193 31.195m0-127.804c-53.269 0-96.609 43.34-96.609 96.609 0 10.373 1.723 20.702 5.123 30.741L559.328 616.879c-18.132-26.128-47.521-41.617-79.302-41.617-36.821 0-70.391 21.065-86.63 54.003L106.68 478.109c-30.288-15.927-52.965-65.817-50.56-111.223 1.248-23.687 9.438-42.071 21.897-49.17 7.916-4.493 17.436-4.099 27.526 1.188l1.916 1.01c75.96 40.022 324.6 170.981 335.063 175.844 16.157 7.47 25.14 10.5 52.659-2.547l513.958-267.3c7.53-2.844 16.315-10.062 16.315-21.023 0-15.205-15.72-21.199-15.765-21.199-29.218-14.018-74.163-35.054-117.987-55.57C798.033 84.26 691.861 34.547 645.23 10.132c-40.253-21.072-72.655-3.311-78.432.282l-11.227 5.555C345.727 119.743 64.898 258.826 48.911 268.553 20.278 285.973 2.547 320.679.252 363.768c-3.586 68.304 31.261 139.506 81.069 165.634l303.172 156.354c6.83 47.306 47.55 82.725 95.532 82.725 52.78 0 95.808-42.546 96.603-95.14L910.541 492.38c16.93 13.233 37.92 20.486 59.416 20.486 53.268 0 96.61-43.341 96.61-96.61s-43.342-96.61-96.61-96.61" fill-rule="evenodd"></path></g></svg>
        </div>
        <div class="tm-content">
            <div class="tm-container">
                <span class="tm-text">
                    Powered by <b>GitBook</b>
                </span>
            </div>
        </div>
    </a>
</div></div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    <a href="#" class="btn pull-left toggle-summary" aria-label="&#x76EE;&#x9304;"><i class="fa fa-align-justify"></i></a>
    <a href="#" class="btn pull-left toggle-search" aria-label="&#x641C;&#x5C0B;"><i class="fa fa-search"></i></a>
    
    <div id="font-settings-wrapper" class="dropdown pull-left">
        <a href="#" class="btn toggle-dropdown" aria-label="&#x5B57;&#x578B;&#x8A2D;&#x5B9A;"><i class="fa fa-font"></i>
        </a>
        <div class="dropdown-menu font-settings">
    <div class="dropdown-caret">
        <span class="caret-outer"></span>
        <span class="caret-inner"></span>
    </div>

    <div class="buttons">
        <button type="button" id="reduce-font-size" class="button size-2">A</button>
        <button type="button" id="enlarge-font-size" class="button size-2">A</button>
    </div>

    <div class="buttons font-family-list">
        <button type="button" data-font="0" class="button">&#x896F;&#x7DDA;&#x9AD4;</button>
        <button type="button" data-font="1" class="button">&#x7121;&#x896F;&#x7DDA;&#x9AD4;</button>
    </div>

    <div class="buttons color-theme-list">
        <button type="button" id="color-theme-preview-0" class="button size-3" data-theme="0">&#x767D;&#x8272;</button>
        <button type="button" id="color-theme-preview-1" class="button size-3" data-theme="1">&#x68D5;&#x8910;&#x8272;</button>
        <button type="button" id="color-theme-preview-2" class="button size-3" data-theme="2">&#x591C;&#x9593;</button>
    </div>
</div>

    </div>

    <!-- Actions Right -->
    
    <div class="dropdown pull-right">
        <a href="#" class="btn toggle-dropdown" aria-label="&#x5206;&#x4EAB;"><i class="fa fa-share-alt"></i>
        </a>
        <div class="dropdown-menu font-settings dropdown-left">
            <div class="dropdown-caret">
                <span class="caret-outer"></span>
                <span class="caret-inner"></span>
            </div>
            <div class="buttons">
                <button type="button" data-sharing="twitter" class="button">
                    &#x5206;&#x4EAB;&#x5230; Twitter
                </button>
                <button type="button" data-sharing="google-plus" class="button">
                    &#x5206;&#x4EAB;&#x5230; Google
                </button>
                <button type="button" data-sharing="facebook" class="button">
                    &#x5206;&#x4EAB;&#x5230; Facebook
                </button>
                <button type="button" data-sharing="weibo" class="button">
                    &#x5206;&#x4EAB;&#x5230; Weibo
                </button>
                <button type="button" data-sharing="instapaper" class="button">
                    &#x5206;&#x4EAB;&#x5230; Instapaper
                </button>
            </div>
        </div>
    </div>
    

    
    <a href="#" target="_blank" class="btn pull-right google-plus-sharing-link sharing-link" data-sharing="google-plus" aria-label="Google"><i class="fa fa-google-plus"></i></a>
    
    
    <a href="#" target="_blank" class="btn pull-right facebook-sharing-link sharing-link" data-sharing="facebook" aria-label="Facebook"><i class="fa fa-facebook"></i></a>
    
    
    <a href="#" target="_blank" class="btn pull-right twitter-sharing-link sharing-link" data-sharing="twitter" aria-label="Twitter"><i class="fa fa-twitter"></i></a>
    
    
    


    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="index.html">ECMAScript 6&#x5165;&#x95E8;</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="%E5%AF%B9%E8%B1%A1%E7%9A%84%E6%89%A9%E5%B1%95">&#x5BF9;&#x8C61;&#x7684;&#x6269;&#x5C55;</h1>
<h2 id="%E5%B1%9E%E6%80%A7%E7%9A%84%E7%AE%80%E6%B4%81%E8%A1%A8%E7%A4%BA%E6%B3%95">&#x5C5E;&#x6027;&#x7684;&#x7B80;&#x6D01;&#x8868;&#x793A;&#x6CD5;</h2>
<p>ES6&#x5141;&#x8BB8;&#x76F4;&#x63A5;&#x5199;&#x5165;&#x53D8;&#x91CF;&#x548C;&#x51FD;&#x6570;&#xFF0C;&#x4F5C;&#x4E3A;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#x548C;&#x65B9;&#x6CD5;&#x3002;&#x8FD9;&#x6837;&#x7684;&#x4E66;&#x5199;&#x66F4;&#x52A0;&#x7B80;&#x6D01;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">var</span> Person = {

  name: <span class="hljs-string">&apos;&#x5F20;&#x4E09;&apos;</span>,

  <span class="hljs-comment">//&#x7B49;&#x540C;&#x4E8E;birth: birth</span>
  birth,

  <span class="hljs-comment">// &#x7B49;&#x540C;&#x4E8E;hello: function ()...</span>
  hello() { <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;&#x6211;&#x7684;&#x540D;&#x5B57;&#x662F;&apos;</span>, <span class="hljs-keyword">this</span>.name); }

};
</code></pre>
<p>&#x8FD9;&#x79CD;&#x5199;&#x6CD5;&#x7528;&#x4E8E;&#x51FD;&#x6570;&#x7684;&#x8FD4;&#x56DE;&#x503C;&#xFF0C;&#x5C06;&#x4F1A;&#x975E;&#x5E38;&#x65B9;&#x4FBF;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getPoint</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">var</span> x = <span class="hljs-number">1</span>;
  <span class="hljs-keyword">var</span> y = <span class="hljs-number">10</span>;

  <span class="hljs-keyword">return</span> {x, y};
}

getPoint()
<span class="hljs-comment">// {x:1, y:10}</span>
</code></pre>
<p>&#x4E0B;&#x9762;&#x662F;&#x4E00;&#x4E2A;&#x7C7B;&#x4F3C;&#x7684;&#x4F8B;&#x5B50;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">let</span> x = <span class="hljs-number">4</span>;
<span class="hljs-keyword">let</span> y = <span class="hljs-number">1</span>;

<span class="hljs-comment">// &#x4E0B;&#x884C;&#x7B49;&#x540C;&#x4E8E; let obj = { x: x, y: y };</span>
<span class="hljs-keyword">let</span> obj = { x, y };
</code></pre>
<h2 id="%E5%B1%9E%E6%80%A7%E5%90%8D%E8%A1%A8%E8%BE%BE%E5%BC%8F">&#x5C5E;&#x6027;&#x540D;&#x8868;&#x8FBE;&#x5F0F;</h2>
<p>JavaScript&#x8BED;&#x8A00;&#x5B9A;&#x4E49;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#xFF0C;&#x6709;&#x4E24;&#x79CD;&#x65B9;&#x6CD5;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-comment">// &#x65B9;&#x6CD5;&#x4E00;</span>
obj.foo = <span class="hljs-literal">true</span>;

<span class="hljs-comment">// &#x65B9;&#x6CD5;&#x4E8C;</span>
obj[<span class="hljs-string">&apos;a&apos;</span>+<span class="hljs-string">&apos;bc&apos;</span>] = <span class="hljs-number">123</span>;
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x7684;&#x65B9;&#x6CD5;&#x4E00;&#x662F;&#x76F4;&#x63A5;&#x7528;&#x6807;&#x8BC6;&#x7B26;&#x4F5C;&#x4E3A;&#x5C5E;&#x6027;&#x540D;&#xFF0C;&#x65B9;&#x6CD5;&#x4E8C;&#x662F;&#x7528;&#x8868;&#x8FBE;&#x5F0F;&#x4F5C;&#x4E3A;&#x5C5E;&#x6027;&#x540D;&#xFF0C;&#x8FD9;&#x65F6;&#x8981;&#x5C06;&#x8868;&#x8FBE;&#x5F0F;&#x653E;&#x5728;&#x65B9;&#x62EC;&#x53F7;&#x4E4B;&#x5185;&#x3002;</p>
<p>&#x4F46;&#x662F;&#xFF0C;&#x5982;&#x679C;&#x4F7F;&#x7528;&#x5B57;&#x9762;&#x91CF;&#x65B9;&#x5F0F;&#x5B9A;&#x4E49;&#x5BF9;&#x8C61;&#xFF08;&#x4F7F;&#x7528;&#x5927;&#x62EC;&#x53F7;&#xFF09;&#xFF0C;&#x5728;ES5&#x4E2D;&#x53EA;&#x80FD;&#x4F7F;&#x7528;&#x65B9;&#x6CD5;&#x4E00;&#xFF08;&#x6807;&#x8BC6;&#x7B26;&#xFF09;&#x5B9A;&#x4E49;&#x5C5E;&#x6027;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">var</span> obj = {
  foo: <span class="hljs-literal">true</span>,
  abc: <span class="hljs-number">123</span>
};
</code></pre>
<p>ES6&#x5141;&#x8BB8;&#x5B57;&#x9762;&#x91CF;&#x5B9A;&#x4E49;&#x5BF9;&#x8C61;&#x65F6;&#xFF0C;&#x7528;&#x65B9;&#x6CD5;&#x4E8C;&#xFF08;&#x8868;&#x8FBE;&#x5F0F;&#xFF09;&#x4F5C;&#x4E3A;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#x540D;&#xFF0C;&#x5373;&#x628A;&#x8868;&#x8FBE;&#x5F0F;&#x653E;&#x5728;&#x65B9;&#x62EC;&#x53F7;&#x5185;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">let</span> propKey = <span class="hljs-string">&apos;foo&apos;</span>;

<span class="hljs-keyword">let</span> obj = {
   [propKey]: <span class="hljs-literal">true</span>,
   [<span class="hljs-string">&apos;a&apos;</span>+<span class="hljs-string">&apos;bc&apos;</span>]: <span class="hljs-number">123</span>
};
</code></pre>
<p>&#x4E0B;&#x9762;&#x662F;&#x53E6;&#x4E00;&#x4E2A;&#x4F8B;&#x5B50;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">var</span> lastWord = <span class="hljs-string">&quot;last word&quot;</span>;

<span class="hljs-keyword">var</span> a = {
    <span class="hljs-string">&quot;first word&quot;</span>: <span class="hljs-string">&quot;hello&quot;</span>,
    [lastWord]: <span class="hljs-string">&quot;world&quot;</span>
};

a[<span class="hljs-string">&quot;first word&quot;</span>] <span class="hljs-comment">// &quot;hello&quot;</span>
a[lastWord] <span class="hljs-comment">// &quot;world&quot;</span>
a[<span class="hljs-string">&quot;last word&quot;</span>] <span class="hljs-comment">// &quot;world&quot;</span>
</code></pre>
<p>&#x8868;&#x8FBE;&#x5F0F;&#x8FD8;&#x53EF;&#x4EE5;&#x7528;&#x4E8E;&#x5B9A;&#x4E49;&#x65B9;&#x6CD5;&#x540D;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">let</span> obj = {
  [<span class="hljs-string">&apos;h&apos;</span>+<span class="hljs-string">&apos;ello&apos;</span>]() {
    <span class="hljs-keyword">return</span> <span class="hljs-string">&apos;hi&apos;</span>;
  }
};

<span class="hljs-built_in">console</span>.log(obj.hello()); <span class="hljs-comment">// hi</span>
</code></pre>
<h2 id="object-is">Object.is()</h2>
<p>Object.is()&#x7528;&#x6765;&#x6BD4;&#x8F83;&#x4E24;&#x4E2A;&#x503C;&#x662F;&#x5426;&#x4E25;&#x683C;&#x76F8;&#x7B49;&#x3002;&#x5B83;&#x4E0E;&#x4E25;&#x683C;&#x6BD4;&#x8F83;&#x8FD0;&#x7B97;&#x7B26;&#xFF08;===&#xFF09;&#x7684;&#x884C;&#x4E3A;&#x57FA;&#x672C;&#x4E00;&#x81F4;&#xFF0C;&#x4E0D;&#x540C;&#x4E4B;&#x5904;&#x53EA;&#x6709;&#x4E24;&#x4E2A;&#xFF1A;&#x4E00;&#x662F;+0&#x4E0D;&#x7B49;&#x4E8E;-0&#xFF0C;&#x4E8C;&#x662F;NaN&#x7B49;&#x4E8E;&#x81EA;&#x8EAB;&#x3002;</p>
<pre><code class="lang-javascript">
+<span class="hljs-number">0</span> === -<span class="hljs-number">0</span> <span class="hljs-comment">//true</span>
<span class="hljs-literal">NaN</span> === <span class="hljs-literal">NaN</span> <span class="hljs-comment">// false</span>

<span class="hljs-built_in">Object</span>.is(+<span class="hljs-number">0</span>, -<span class="hljs-number">0</span>) <span class="hljs-comment">// false</span>
<span class="hljs-built_in">Object</span>.is(<span class="hljs-literal">NaN</span>, <span class="hljs-literal">NaN</span>) <span class="hljs-comment">// true</span>
</code></pre>
<h2 id="object-assign">Object.assign()</h2>
<p>Object.assign&#x65B9;&#x6CD5;&#x7528;&#x6765;&#x5C06;&#x6E90;&#x5BF9;&#x8C61;&#xFF08;source&#xFF09;&#x7684;&#x6240;&#x6709;&#x53EF;&#x679A;&#x4E3E;&#x5C5E;&#x6027;&#xFF0C;&#x590D;&#x5236;&#x5230;&#x76EE;&#x6807;&#x5BF9;&#x8C61;&#xFF08;target&#xFF09;&#x3002;&#x5B83;&#x81F3;&#x5C11;&#x9700;&#x8981;&#x4E24;&#x4E2A;&#x5BF9;&#x8C61;&#x4F5C;&#x4E3A;&#x53C2;&#x6570;&#xFF0C;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x76EE;&#x6807;&#x5BF9;&#x8C61;&#xFF0C;&#x540E;&#x9762;&#x7684;&#x53C2;&#x6570;&#x90FD;&#x662F;&#x6E90;&#x5BF9;&#x8C61;&#x3002;&#x53EA;&#x8981;&#x6709;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x4E0D;&#x662F;&#x5BF9;&#x8C61;&#xFF0C;&#x5C31;&#x4F1A;&#x629B;&#x51FA;TypeError&#x9519;&#x8BEF;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">var</span> target = { a: <span class="hljs-number">1</span> };

<span class="hljs-keyword">var</span> source1 = { b: <span class="hljs-number">2</span> };
<span class="hljs-keyword">var</span> source2 = { c: <span class="hljs-number">3</span> };

<span class="hljs-built_in">Object</span>.assign(target, source1, source2);
target <span class="hljs-comment">// {a:1, b:2, c:3}</span>
</code></pre>
<p>&#x6CE8;&#x610F;&#xFF0C;&#x5982;&#x679C;&#x76EE;&#x6807;&#x5BF9;&#x8C61;&#x4E0E;&#x6E90;&#x5BF9;&#x8C61;&#x6709;&#x540C;&#x540D;&#x5C5E;&#x6027;&#xFF0C;&#x6216;&#x591A;&#x4E2A;&#x6E90;&#x5BF9;&#x8C61;&#x6709;&#x540C;&#x540D;&#x5C5E;&#x6027;&#xFF0C;&#x5219;&#x540E;&#x9762;&#x7684;&#x5C5E;&#x6027;&#x4F1A;&#x8986;&#x76D6;&#x524D;&#x9762;&#x7684;&#x5C5E;&#x6027;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">var</span> target = { a: <span class="hljs-number">1</span>, b: <span class="hljs-number">1</span> };

<span class="hljs-keyword">var</span> source1 = { b: <span class="hljs-number">2</span>, c: <span class="hljs-number">2</span> };
<span class="hljs-keyword">var</span> source2 = { c: <span class="hljs-number">3</span> };

<span class="hljs-built_in">Object</span>.assign(target, source1, source2);
target <span class="hljs-comment">// {a:1, b:2, c:3}</span>
</code></pre>
<p>assign&#x65B9;&#x6CD5;&#x6709;&#x5F88;&#x591A;&#x7528;&#x5904;&#x3002;</p>
<p><strong>&#xFF08;1&#xFF09;&#x4E3A;&#x5BF9;&#x8C61;&#x6DFB;&#x52A0;&#x5C5E;&#x6027;</strong></p>
<pre><code class="lang-javascript">
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Point</span> </span>{
  constructor(x, y) {
    <span class="hljs-built_in">Object</span>.assign(<span class="hljs-keyword">this</span>, {x, y});
  }
}
</code></pre>
<p>&#x4E0A;&#x9762;&#x65B9;&#x6CD5;&#x901A;&#x8FC7;assign&#x65B9;&#x6CD5;&#xFF0C;&#x5C06;x&#x5C5E;&#x6027;&#x548C;y&#x5C5E;&#x6027;&#x6DFB;&#x52A0;&#x5230;Point&#x7C7B;&#x7684;&#x5BF9;&#x8C61;&#x5B9E;&#x4F8B;&#x3002;</p>
<p><strong>&#xFF08;2&#xFF09;&#x4E3A;&#x5BF9;&#x8C61;&#x6DFB;&#x52A0;&#x65B9;&#x6CD5;</strong></p>
<pre><code class="lang-javascript">
<span class="hljs-built_in">Object</span>.assign(SomeClass.prototype, {
  someMethod(arg1, arg2) {
    &#xB7;&#xB7;&#xB7;
  },
  anotherMethod() {
    &#xB7;&#xB7;&#xB7;
  }
});

<span class="hljs-comment">// &#x7B49;&#x540C;&#x4E8E;&#x4E0B;&#x9762;&#x7684;&#x5199;&#x6CD5;</span>
SomeClass.prototype.someMethod = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">arg1, arg2</span>) </span>{
  &#xB7;&#xB7;&#xB7;
};
SomeClass.prototype.anotherMethod = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  &#xB7;&#xB7;&#xB7;
};
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4F7F;&#x7528;&#x4E86;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;&#x7684;&#x7B80;&#x6D01;&#x8868;&#x793A;&#x6CD5;&#xFF0C;&#x76F4;&#x63A5;&#x5C06;&#x4E24;&#x4E2A;&#x51FD;&#x6570;&#x653E;&#x5728;&#x5927;&#x62EC;&#x53F7;&#x4E2D;&#xFF0C;&#x518D;&#x4F7F;&#x7528;assign&#x65B9;&#x6CD5;&#x6DFB;&#x52A0;&#x5230;SomeClass.prototype&#x4E4B;&#x4E2D;&#x3002;</p>
<p><strong>&#xFF08;3&#xFF09;&#x514B;&#x9686;&#x5BF9;&#x8C61;</strong></p>
<pre><code class="lang-javascript">
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">clone</span>(<span class="hljs-params">origin</span>) </span>{
  <span class="hljs-keyword">return</span> <span class="hljs-built_in">Object</span>.assign({}, origin);
}
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x5C06;&#x539F;&#x59CB;&#x5BF9;&#x8C61;&#x62F7;&#x8D1D;&#x5230;&#x4E00;&#x4E2A;&#x7A7A;&#x5BF9;&#x8C61;&#xFF0C;&#x5C31;&#x5F97;&#x5230;&#x4E86;&#x539F;&#x59CB;&#x5BF9;&#x8C61;&#x7684;&#x514B;&#x9686;&#x3002;</p>
<p>&#x4E0D;&#x8FC7;&#xFF0C;&#x91C7;&#x7528;&#x8FD9;&#x79CD;&#x65B9;&#x6CD5;&#x514B;&#x9686;&#xFF0C;&#x53EA;&#x80FD;&#x514B;&#x9686;&#x539F;&#x59CB;&#x5BF9;&#x8C61;&#x81EA;&#x8EAB;&#x7684;&#x503C;&#xFF0C;&#x4E0D;&#x80FD;&#x514B;&#x9686;&#x5B83;&#x7EE7;&#x627F;&#x7684;&#x503C;&#x3002;&#x5982;&#x679C;&#x60F3;&#x8981;&#x4FDD;&#x6301;&#x7EE7;&#x627F;&#x94FE;&#xFF0C;&#x53EF;&#x4EE5;&#x91C7;&#x7528;&#x4E0B;&#x9762;&#x7684;&#x4EE3;&#x7801;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">clone</span>(<span class="hljs-params">origin</span>) </span>{
  <span class="hljs-keyword">let</span> originProto = <span class="hljs-built_in">Object</span>.getPrototypeOf(origin);
  <span class="hljs-keyword">return</span> <span class="hljs-built_in">Object</span>.assign(<span class="hljs-built_in">Object</span>.create(originProto), origin);
}
</code></pre>
<p><strong>&#xFF08;4&#xFF09;&#x4E3A;&#x5C5E;&#x6027;&#x6307;&#x5B9A;&#x9ED8;&#x8BA4;&#x503C;</strong></p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">const</span> DEFAULTS = {
  logLevel: <span class="hljs-number">0</span>,
  outputFormat: <span class="hljs-string">&apos;html&apos;</span>
};

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">processContent</span>(<span class="hljs-params">options</span>) </span>{
  <span class="hljs-keyword">let</span> options = <span class="hljs-built_in">Object</span>.assign({}, DEFAULTS, options);
}
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;DEFAULTS&#x5BF9;&#x8C61;&#x662F;&#x9ED8;&#x8BA4;&#x503C;&#xFF0C;options&#x5BF9;&#x8C61;&#x662F;&#x7528;&#x6237;&#x63D0;&#x4F9B;&#x7684;&#x53C2;&#x6570;&#x3002;assign&#x65B9;&#x6CD5;&#x5C06;DEFAULTS&#x548C;options&#x5408;&#x5E76;&#x6210;&#x4E00;&#x4E2A;&#x65B0;&#x5BF9;&#x8C61;&#xFF0C;&#x5982;&#x679C;&#x4E24;&#x8005;&#x6709;&#x540C;&#x540D;&#x5C5E;&#x6027;&#xFF0C;&#x5219;option&#x7684;&#x5C5E;&#x6027;&#x503C;&#x4F1A;&#x8986;&#x76D6;DEFAULTS&#x7684;&#x5C5E;&#x6027;&#x503C;&#x3002;</p>
<h2 id="-proto-%E5%B1%9E%E6%80%A7%EF%BC%8Cobject-setprototypeof-%EF%BC%8Cobject-getprototypeof"><strong>proto</strong>&#x5C5E;&#x6027;&#xFF0C;Object.setPrototypeOf()&#xFF0C;Object.getPrototypeOf()</h2>
<p><strong>&#xFF08;1&#xFF09;<strong>proto</strong>&#x5C5E;&#x6027;</strong></p>
<p><strong>proto</strong>&#x5C5E;&#x6027;&#xFF0C;&#x7528;&#x6765;&#x8BFB;&#x53D6;&#x6216;&#x8BBE;&#x7F6E;&#x5F53;&#x524D;&#x5BF9;&#x8C61;&#x7684;prototype&#x5BF9;&#x8C61;&#x3002;&#x8BE5;&#x5C5E;&#x6027;&#x4E00;&#x5EA6;&#x88AB;&#x6B63;&#x5F0F;&#x5199;&#x5165;ES6&#x8349;&#x6848;&#xFF0C;&#x4F46;&#x540E;&#x6765;&#x53C8;&#x88AB;&#x79FB;&#x9664;&#x3002;&#x76EE;&#x524D;&#xFF0C;&#x6240;&#x6709;&#x6D4F;&#x89C8;&#x5668;&#xFF08;&#x5305;&#x62EC;IE11&#xFF09;&#x90FD;&#x90E8;&#x7F72;&#x4E86;&#x8FD9;&#x4E2A;&#x5C5E;&#x6027;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-comment">// es6&#x7684;&#x5199;&#x6CD5;</span>

<span class="hljs-keyword">var</span> obj = {
  __proto__: someOtherObj,
  method: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{ ... }
}

<span class="hljs-comment">// es5&#x7684;&#x5199;&#x6CD5;</span>

<span class="hljs-keyword">var</span> obj = <span class="hljs-built_in">Object</span>.create(someOtherObj);
obj.method = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{ ... }
</code></pre>
<p>&#x6709;&#x4E86;&#x8FD9;&#x4E2A;&#x5C5E;&#x6027;&#xFF0C;&#x5B9E;&#x9645;&#x4E0A;&#x5DF2;&#x7ECF;&#x4E0D;&#x9700;&#x8981;&#x901A;&#x8FC7;Object.create()&#x6765;&#x751F;&#x6210;&#x65B0;&#x5BF9;&#x8C61;&#x4E86;&#x3002;</p>
<p><strong>&#xFF08;2&#xFF09;Object.setPrototypeOf()</strong></p>
<p>Object.setPrototypeOf&#x65B9;&#x6CD5;&#x7684;&#x4F5C;&#x7528;&#x4E0E;<strong>proto</strong>&#x76F8;&#x540C;&#xFF0C;&#x7528;&#x6765;&#x8BBE;&#x7F6E;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x7684;prototype&#x5BF9;&#x8C61;&#x3002;&#x5B83;&#x662F;ES6&#x6B63;&#x5F0F;&#x63A8;&#x8350;&#x7684;&#x8BBE;&#x7F6E;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x7684;&#x65B9;&#x6CD5;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-comment">// &#x683C;&#x5F0F;</span>
<span class="hljs-built_in">Object</span>.setPrototypeOf(object, prototype)

<span class="hljs-comment">// &#x7528;&#x6CD5;</span>
<span class="hljs-keyword">var</span> o = <span class="hljs-built_in">Object</span>.setPrototypeOf({}, <span class="hljs-literal">null</span>);
</code></pre>
<p>&#x8BE5;&#x65B9;&#x6CD5;&#x7B49;&#x540C;&#x4E8E;&#x4E0B;&#x9762;&#x7684;&#x51FD;&#x6570;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">obj, proto</span>) </span>{
  obj.__proto__ = proto;
  <span class="hljs-keyword">return</span> obj;
}
</code></pre>
<p><strong>&#xFF08;3&#xFF09;Object.getPrototypeOf()</strong></p>
<p>&#x8BE5;&#x65B9;&#x6CD5;&#x4E0E;setPrototypeOf&#x65B9;&#x6CD5;&#x914D;&#x5957;&#xFF0C;&#x7528;&#x4E8E;&#x8BFB;&#x53D6;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x7684;prototype&#x5BF9;&#x8C61;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-built_in">Object</span>.getPrototypeOf(obj)
</code></pre>
<h2 id="symbol">Symbol</h2>
<p>ES6&#x5F15;&#x5165;&#x4E86;&#x4E00;&#x79CD;&#x65B0;&#x7684;&#x539F;&#x59CB;&#x6570;&#x636E;&#x7C7B;&#x578B;Symbol&#xFF0C;&#x8868;&#x793A;&#x72EC;&#x4E00;&#x65E0;&#x4E8C;&#x7684;ID&#x3002;&#x5B83;&#x901A;&#x8FC7;Symbol&#x51FD;&#x6570;&#x751F;&#x6210;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">let</span> symbol1 = <span class="hljs-built_in">Symbol</span>();

<span class="hljs-keyword">typeof</span> symbol
<span class="hljs-comment">// &quot;symbol&quot;</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x53D8;&#x91CF;symbol1&#x5C31;&#x662F;&#x4E00;&#x4E2A;&#x72EC;&#x4E00;&#x65E0;&#x4E8C;&#x7684;ID&#x3002;typeof&#x8FD0;&#x7B97;&#x7B26;&#x7684;&#x7ED3;&#x679C;&#xFF0C;&#x8868;&#x660E;&#x53D8;&#x91CF;symbol1&#x662F;Symbol&#x6570;&#x636E;&#x7C7B;&#x578B;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x5B57;&#x7B26;&#x4E32;&#x4E4B;&#x7C7B;&#x7684;&#x5176;&#x4ED6;&#x7C7B;&#x578B;&#x3002;</p>
<p>Symbol&#x51FD;&#x6570;&#x53EF;&#x4EE5;&#x63A5;&#x53D7;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x4F5C;&#x4E3A;&#x53C2;&#x6570;&#xFF0C;&#x8868;&#x793A;Symbol&#x5B9E;&#x4F8B;&#x7684;&#x540D;&#x79F0;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">var</span> mySymbol = <span class="hljs-built_in">Symbol</span>(<span class="hljs-string">&apos;Test&apos;</span>);

mySymbol.name
<span class="hljs-comment">// Test</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x8868;&#x793A;&#xFF0C;Symbol&#x51FD;&#x6570;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x53C2;&#x6570;&#xFF0C;&#x7528;&#x6765;&#x6307;&#x5B9A;&#x751F;&#x6210;&#x7684;Symbol&#x7684;&#x540D;&#x79F0;&#xFF0C;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;name&#x5C5E;&#x6027;&#x8BFB;&#x53D6;&#x3002;&#x4E4B;&#x6240;&#x4EE5;&#x8981;&#x65B0;&#x589E;name&#x5C5E;&#x6027;&#xFF0C;&#x662F;&#x56E0;&#x4E3A;&#x952E;&#x540D;&#x662F;Symbol&#x7C7B;&#x578B;&#xFF0C;&#x800C;&#x6709;&#x4E9B;&#x573A;&#x5408;&#x9700;&#x8981;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x7C7B;&#x578B;&#x7684;&#x503C;&#x6765;&#x6307;&#x4EE3;&#x8FD9;&#x4E2A;&#x952E;&#x3002;</p>
<p>&#x6CE8;&#x610F;&#xFF0C;Symbol&#x51FD;&#x6570;&#x524D;&#x4E0D;&#x80FD;&#x4F7F;&#x7528;new&#x547D;&#x4EE4;&#xFF0C;&#x5426;&#x5219;&#x4F1A;&#x62A5;&#x9519;&#x3002;&#x8FD9;&#x662F;&#x56E0;&#x4E3A;&#x751F;&#x6210;&#x7684;Symbol&#x662F;&#x4E00;&#x4E2A;&#x539F;&#x59CB;&#x7C7B;&#x578B;&#x7684;&#x503C;&#xFF0C;&#x4E0D;&#x662F;&#x5BF9;&#x8C61;&#x3002;</p>
<p>Symbol&#x7C7B;&#x578B;&#x7684;&#x503C;&#x4E0D;&#x80FD;&#x4E0E;&#x5176;&#x4ED6;&#x7C7B;&#x578B;&#x7684;&#x503C;&#x8FDB;&#x884C;&#x8FD0;&#x7B97;&#xFF0C;&#x4F1A;&#x62A5;&#x9519;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">var</span> sym = <span class="hljs-built_in">Symbol</span>(<span class="hljs-string">&apos;My symbol&apos;</span>);
<span class="hljs-string">&apos;&apos;</span> + sym
<span class="hljs-comment">// TypeError: Cannot convert a Symbol value to a string</span>
</code></pre>
<p>&#x4F46;&#x662F;&#xFF0C;Symbol&#x7C7B;&#x578B;&#x7684;&#x503C;&#x53EF;&#x4EE5;&#x8F6C;&#x4E3A;&#x5B57;&#x7B26;&#x4E32;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-built_in">String</span>(sym)
<span class="hljs-comment">// &apos;Symbol(My symbol)&apos;</span>

sym.toString()
<span class="hljs-comment">// &apos;Symbol(My symbol)&apos;</span>
</code></pre>
<p>symbol&#x7684;&#x6700;&#x5927;&#x7279;&#x70B9;&#xFF0C;&#x5C31;&#x662F;&#x6BCF;&#x4E00;&#x4E2A;Symbol&#x90FD;&#x662F;&#x4E0D;&#x76F8;&#x7B49;&#x7684;&#xFF0C;&#x4FDD;&#x8BC1;&#x4EA7;&#x751F;&#x4E00;&#x4E2A;&#x72EC;&#x4E00;&#x65E0;&#x4E8C;&#x7684;&#x503C;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">let</span> w1 = <span class="hljs-built_in">Symbol</span>();
<span class="hljs-keyword">let</span> w2 = <span class="hljs-built_in">Symbol</span>();
<span class="hljs-keyword">let</span> w3 = <span class="hljs-built_in">Symbol</span>();

w1 === w2 <span class="hljs-comment">// false</span>
w1 === w3 <span class="hljs-comment">// false</span>
w2 === w3 <span class="hljs-comment">// false</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params">w</span>) </span>{
  <span class="hljs-keyword">switch</span> (w) {
    <span class="hljs-keyword">case</span> w1:
      ...
    <span class="hljs-keyword">case</span> w2:
      ...
    <span class="hljs-keyword">case</span> w3:
      ...
  }
}
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;w1&#x3001;w2&#x3001;w3&#x4E09;&#x4E2A;&#x53D8;&#x91CF;&#x90FD;&#x7B49;&#x4E8E;<code>Symbol()</code>&#xFF0C;&#x4F46;&#x662F;&#x5B83;&#x4EEC;&#x7684;&#x503C;&#x662F;&#x4E0D;&#x76F8;&#x7B49;&#x7684;&#x3002;</p>
<p>&#x7531;&#x4E8E;&#x8FD9;&#x79CD;&#x7279;&#x70B9;&#xFF0C;Symbol&#x7C7B;&#x578B;&#x9002;&#x5408;&#x4F5C;&#x4E3A;&#x6807;&#x8BC6;&#x7B26;&#xFF0C;&#x7528;&#x4E8E;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#x540D;&#xFF0C;&#x4FDD;&#x8BC1;&#x4E86;&#x5C5E;&#x6027;&#x540D;&#x4E4B;&#x95F4;&#x4E0D;&#x4F1A;&#x53D1;&#x751F;&#x51B2;&#x7A81;&#x3002;&#x5982;&#x679C;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x7531;&#x591A;&#x4E2A;&#x6A21;&#x5757;&#x6784;&#x6210;&#xFF0C;&#x8FD9;&#x6837;&#x5C31;&#x4E0D;&#x4F1A;&#x51FA;&#x73B0;&#x540C;&#x540D;&#x7684;&#x5C5E;&#x6027;&#xFF0C;&#x4E5F;&#x5C31;&#x9632;&#x6B62;&#x4E86;&#x952E;&#x503C;&#x88AB;&#x4E0D;&#x5C0F;&#x5FC3;&#x6539;&#x5199;&#x6216;&#x8986;&#x76D6;&#x3002;Symbol&#x7C7B;&#x578B;&#x8FD8;&#x53EF;&#x4EE5;&#x7528;&#x4E8E;&#x5B9A;&#x4E49;&#x4E00;&#x7EC4;&#x5E38;&#x91CF;&#xFF0C;&#x9632;&#x6B62;&#x5B83;&#x4EEC;&#x7684;&#x503C;&#x53D1;&#x751F;&#x51B2;&#x7A81;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">var</span> mySymbol = <span class="hljs-built_in">Symbol</span>();

<span class="hljs-comment">// &#x7B2C;&#x4E00;&#x79CD;&#x5199;&#x6CD5;</span>
<span class="hljs-keyword">var</span> a = {};
a[mySymbol] = <span class="hljs-string">&apos;Hello!&apos;</span>;

<span class="hljs-comment">// &#x7B2C;&#x4E8C;&#x79CD;&#x5199;&#x6CD5;</span>
<span class="hljs-keyword">var</span> a = {
   [mySymbol]: <span class="hljs-number">123</span>
};

<span class="hljs-comment">// &#x7B2C;&#x4E09;&#x79CD;&#x5199;&#x6CD5;</span>
<span class="hljs-keyword">var</span> a = {};
<span class="hljs-built_in">Object</span>.defineProperty(a, mySymbol, { value: <span class="hljs-string">&apos;Hello!&apos;</span> });

a[mySymbol] <span class="hljs-comment">// &quot;Hello!&quot;</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x901A;&#x8FC7;&#x65B9;&#x62EC;&#x53F7;&#x7ED3;&#x6784;&#x548C;Object.defineProperty&#x4E24;&#x79CD;&#x65B9;&#x6CD5;&#xFF0C;&#x5C06;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#x540D;&#x6307;&#x5B9A;&#x4E3A;&#x4E00;&#x4E2A;Symbol&#x503C;&#x3002;</p>
<p>&#x6CE8;&#x610F;&#xFF0C;&#x4E0D;&#x80FD;&#x4F7F;&#x7528;&#x70B9;&#x7ED3;&#x6784;&#xFF0C;&#x5C06;Symbol&#x503C;&#x4F5C;&#x4E3A;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#x540D;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">var</span> a = {};
<span class="hljs-keyword">var</span> mySymbol = <span class="hljs-built_in">Symbol</span>();

a.mySymbol = <span class="hljs-string">&apos;Hello!&apos;</span>;

a[mySymbol] <span class="hljs-comment">// undefined</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;mySymbol&#x5C5E;&#x6027;&#x7684;&#x503C;&#x4E3A;&#x672A;&#x5B9A;&#x4E49;&#xFF0C;&#x539F;&#x56E0;&#x5728;&#x4E8E;<code>a.mySymbol</code>&#x8FD9;&#x6837;&#x7684;&#x5199;&#x6CD5;&#xFF0C;&#x5E76;&#x4E0D;&#x662F;&#x628A;&#x4E00;&#x4E2A;Symbol&#x503C;&#x5F53;&#x4F5C;&#x5C5E;&#x6027;&#x540D;&#xFF0C;&#x800C;&#x662F;&#x628A;mySymbol&#x8FD9;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x5F53;&#x4F5C;&#x5C5E;&#x6027;&#x540D;&#x8FDB;&#x884C;&#x8D4B;&#x503C;&#xFF0C;&#x8FD9;&#x662F;&#x56E0;&#x4E3A;&#x70B9;&#x7ED3;&#x6784;&#x4E2D;&#x7684;&#x5C5E;&#x6027;&#x540D;&#x6C38;&#x8FDC;&#x90FD;&#x662F;&#x5B57;&#x7B26;&#x4E32;&#x3002;</p>
<p>&#x4E0B;&#x9762;&#x7684;&#x5199;&#x6CD5;&#x4E3A;Map&#x7ED3;&#x6784;&#x6DFB;&#x52A0;&#x4E86;&#x4E00;&#x4E2A;&#x6210;&#x5458;&#xFF0C;&#x4F46;&#x662F;&#x8BE5;&#x6210;&#x5458;&#x6C38;&#x8FDC;&#x65E0;&#x6CD5;&#x88AB;&#x5F15;&#x7528;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">let</span> a = <span class="hljs-built_in">Map</span>();
a.set(<span class="hljs-built_in">Symbol</span>(), <span class="hljs-string">&apos;Noise&apos;</span>);
a.size <span class="hljs-comment">// 1</span>
</code></pre>
<p>&#x4E3A;Symbol&#x51FD;&#x6570;&#x6DFB;&#x52A0;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x5C31;&#x53EF;&#x4EE5;&#x5F15;&#x7528;&#x4E86;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">let</span> a = <span class="hljs-built_in">Map</span>();
a.set(<span class="hljs-built_in">Symbol</span>(<span class="hljs-string">&apos;my_key&apos;</span>), <span class="hljs-string">&apos;Noise&apos;</span>);
</code></pre>
<p>&#x5982;&#x679C;&#x8981;&#x5728;&#x5BF9;&#x8C61;&#x5185;&#x90E8;&#x4F7F;&#x7528;Symbol&#x5C5E;&#x6027;&#x540D;&#xFF0C;&#x5FC5;&#x987B;&#x91C7;&#x7528;&#x5C5E;&#x6027;&#x540D;&#x8868;&#x8FBE;&#x5F0F;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">let</span> specialMethod = <span class="hljs-built_in">Symbol</span>();

<span class="hljs-keyword">let</span> obj = {
  [specialMethod]: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">arg</span>) </span>{ ... }
};

obj[specialMethod](<span class="hljs-number">123</span>);
</code></pre>
<p>&#x91C7;&#x7528;&#x589E;&#x5F3A;&#x7684;&#x5BF9;&#x8C61;&#x5199;&#x6CD5;&#xFF0C;&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x7684;obj&#x5BF9;&#x8C61;&#x53EF;&#x4EE5;&#x5199;&#x5F97;&#x66F4;&#x7B80;&#x6D01;&#x4E00;&#x4E9B;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">let</span> obj = {
  [specialMethod](arg) { ... }
};
</code></pre>
<p>Symbol&#x7C7B;&#x578B;&#x4F5C;&#x4E3A;&#x5C5E;&#x6027;&#x540D;&#xFF0C;&#x4E0D;&#x4F1A;&#x51FA;&#x73B0;&#x5728;for...in&#x5FAA;&#x73AF;&#x4E2D;&#xFF0C;&#x4E5F;&#x4E0D;&#x4F1A;&#x88AB;Object.keys()&#x3001;Object.getOwnPropertyNames()&#x8FD4;&#x56DE;&#xFF0C;&#x4F46;&#x662F;&#x6709;&#x4E00;&#x4E2A;&#x5BF9;&#x5E94;&#x7684;Object.getOwnPropertySymbols&#x65B9;&#x6CD5;&#xFF0C;&#x4EE5;&#x53CA;Object.getOwnPropertyKeys&#x65B9;&#x6CD5;&#x90FD;&#x53EF;&#x4EE5;&#x83B7;&#x53D6;Symbol&#x5C5E;&#x6027;&#x540D;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">var</span> obj = {};

<span class="hljs-keyword">var</span> foo = <span class="hljs-built_in">Symbol</span>(<span class="hljs-string">&quot;foo&quot;</span>);

<span class="hljs-built_in">Object</span>.defineProperty(obj, foo, {
    value: <span class="hljs-string">&quot;foobar&quot;</span>,
});

<span class="hljs-built_in">Object</span>.getOwnPropertyNames(obj)
<span class="hljs-comment">// []</span>

<span class="hljs-built_in">Object</span>.getOwnPropertySymbols(obj)
<span class="hljs-comment">// [Symbol(foo)]</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x4F7F;&#x7528;Object.getOwnPropertyNames&#x65B9;&#x6CD5;&#x5F97;&#x4E0D;&#x5230;Symbol&#x5C5E;&#x6027;&#x540D;&#xFF0C;&#x9700;&#x8981;&#x4F7F;&#x7528;Object.getOwnPropertySymbols&#x65B9;&#x6CD5;&#x3002;</p>
<p>Reflect.ownKeys&#x65B9;&#x6CD5;&#x8FD4;&#x56DE;&#x6240;&#x6709;&#x7C7B;&#x578B;&#x7684;&#x952E;&#x540D;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">let</span> obj = {
  [<span class="hljs-built_in">Symbol</span>(<span class="hljs-string">&apos;my_key&apos;</span>)]: <span class="hljs-number">1</span>,
  enum: <span class="hljs-number">2</span>,
  nonEnum: <span class="hljs-number">3</span>
};

<span class="hljs-built_in">Reflect</span>.ownKeys(obj)
<span class="hljs-comment">// [Symbol(my_key), &apos;enum&apos;, &apos;nonEnum&apos;]</span>
</code></pre>
<h2 id="proxy">Proxy</h2>
<p>Proxy&#x7528;&#x4E8E;&#x4FEE;&#x6539;&#x67D0;&#x4E9B;&#x64CD;&#x4F5C;&#x7684;&#x9ED8;&#x8BA4;&#x884C;&#x4E3A;&#xFF0C;&#x7B49;&#x540C;&#x4E8E;&#x5728;&#x8BED;&#x8A00;&#x5C42;&#x9762;&#x505A;&#x51FA;&#x4FEE;&#x6539;&#xFF0C;&#x6240;&#x4EE5;&#x5C5E;&#x4E8E;&#x4E00;&#x79CD;&#x201C;&#x5143;&#x7F16;&#x7A0B;&#x201D;&#xFF08;meta programming&#xFF09;&#xFF0C;&#x5373;&#x5BF9;&#x7F16;&#x7A0B;&#x8BED;&#x8A00;&#x8FDB;&#x884C;&#x7F16;&#x7A0B;&#x3002;</p>
<p>Proxy&#x53EF;&#x4EE5;&#x7406;&#x89E3;&#x6210;&#x5728;&#x76EE;&#x6807;&#x5BF9;&#x8C61;&#x4E4B;&#x524D;&#xFF0C;&#x67B6;&#x8BBE;&#x4E00;&#x5C42;&#x201C;&#x62E6;&#x622A;&#x201D;&#xFF0C;&#x5916;&#x754C;&#x5BF9;&#x8BE5;&#x5BF9;&#x8C61;&#x7684;&#x8BBF;&#x95EE;&#xFF0C;&#x90FD;&#x5FC5;&#x987B;&#x5148;&#x901A;&#x8FC7;&#x8FD9;&#x5C42;&#x62E6;&#x622A;&#xFF0C;&#x56E0;&#x6B64;&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x79CD;&#x673A;&#x5236;&#xFF0C;&#x53EF;&#x4EE5;&#x5BF9;&#x5916;&#x754C;&#x7684;&#x8BBF;&#x95EE;&#x8FDB;&#x884C;&#x8FC7;&#x6EE4;&#x548C;&#x6539;&#x5199;&#x3002;proxy&#x8FD9;&#x4E2A;&#x8BCD;&#x7684;&#x539F;&#x610F;&#x662F;&#x4EE3;&#x7406;&#xFF0C;&#x7528;&#x5728;&#x8FD9;&#x91CC;&#x8868;&#x793A;&#x7531;&#x5B83;&#x6765;&#x201C;&#x4EE3;&#x7406;&#x201D;&#x67D0;&#x4E9B;&#x64CD;&#x4F5C;&#x3002;</p>
<p>ES6&#x539F;&#x751F;&#x63D0;&#x4F9B;Proxy&#x6784;&#x9020;&#x51FD;&#x6570;&#xFF0C;&#x7528;&#x6765;&#x751F;&#x6210;Proxy&#x5B9E;&#x4F8B;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">var</span> proxy = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Proxy</span>({}, {
  get: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">target, property</span>) </span>{
    <span class="hljs-keyword">return</span> <span class="hljs-number">35</span>;
  }
});

proxy.time <span class="hljs-comment">// 35</span>
proxy.name <span class="hljs-comment">// 35</span>
proxy.title <span class="hljs-comment">// 35</span>
</code></pre>
<p>&#x4F5C;&#x4E3A;&#x6784;&#x9020;&#x51FD;&#x6570;&#xFF0C;Proxy&#x63A5;&#x53D7;&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#x3002;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x6240;&#x8981;&#x4EE3;&#x7406;&#x7684;&#x76EE;&#x6807;&#x5BF9;&#x8C61;&#xFF08;&#x4E0A;&#x4F8B;&#x662F;&#x4E00;&#x4E2A;&#x7A7A;&#x5BF9;&#x8C61;&#xFF09;&#xFF0C;&#x5373;&#x5982;&#x679C;&#x6CA1;&#x6709;Proxy&#x7684;&#x4ECB;&#x5165;&#xFF0C;&#x64CD;&#x4F5C;&#x539F;&#x6765;&#x8981;&#x8BBF;&#x95EE;&#x7684;&#x5C31;&#x662F;&#x8FD9;&#x4E2A;&#x5BF9;&#x8C61;&#xFF1B;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x4E00;&#x4E2A;&#x8BBE;&#x7F6E;&#x5BF9;&#x8C61;&#xFF0C;&#x5BF9;&#x4E8E;&#x6BCF;&#x4E00;&#x4E2A;&#x88AB;&#x4EE3;&#x7406;&#x7684;&#x64CD;&#x4F5C;&#xFF0C;&#x9700;&#x8981;&#x63D0;&#x4F9B;&#x4E00;&#x4E2A;&#x5BF9;&#x5E94;&#x7684;&#x5904;&#x7406;&#x51FD;&#x6570;&#xFF0C;&#x8BE5;&#x51FD;&#x6570;&#x5C06;&#x62E6;&#x622A;&#x5BF9;&#x5E94;&#x7684;&#x64CD;&#x4F5C;&#x3002;&#x6BD4;&#x5982;&#xFF0C;&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x8BBE;&#x7F6E;&#x5BF9;&#x8C61;&#x6709;&#x4E00;&#x4E2A;get&#x65B9;&#x6CD5;&#xFF0C;&#x7528;&#x6765;&#x62E6;&#x622A;&#x5BF9;&#x76EE;&#x6807;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;&#x7684;&#x8BBF;&#x95EE;&#x8BF7;&#x6C42;&#x3002;get&#x65B9;&#x6CD5;&#x7684;&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#x5206;&#x522B;&#x662F;&#x76EE;&#x6807;&#x5BF9;&#x8C61;&#x548C;&#x6240;&#x8981;&#x8BBF;&#x95EE;&#x7684;&#x5C5E;&#x6027;&#x3002;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#xFF0C;&#x7531;&#x4E8E;&#x62E6;&#x622A;&#x51FD;&#x6570;&#x603B;&#x662F;&#x8FD4;&#x56DE;35&#xFF0C;&#x6240;&#x4EE5;&#x8BBF;&#x95EE;&#x4EFB;&#x4F55;&#x5C5E;&#x6027;&#x90FD;&#x5F97;&#x5230;35&#x3002;</p>
<p>&#x6CE8;&#x610F;&#xFF0C;&#x8981;&#x4F7F;&#x5F97;Proxy&#x8D77;&#x4F5C;&#x7528;&#xFF0C;&#x5FC5;&#x987B;&#x9488;&#x5BF9;Proxy&#x5B9E;&#x4F8B;&#xFF08;&#x4E0A;&#x4F8B;&#x662F;proxy&#x5BF9;&#x8C61;&#xFF09;&#x8FDB;&#x884C;&#x64CD;&#x4F5C;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x9488;&#x5BF9;&#x76EE;&#x6807;&#x5BF9;&#x8C61;&#xFF08;&#x4E0A;&#x4F8B;&#x662F;&#x7A7A;&#x5BF9;&#x8C61;&#xFF09;&#x8FDB;&#x884C;&#x64CD;&#x4F5C;&#x3002;</p>
<p>Proxy&#x5B9E;&#x4F8B;&#x4E5F;&#x53EF;&#x4EE5;&#x4F5C;&#x4E3A;&#x5176;&#x4ED6;&#x5BF9;&#x8C61;&#x7684;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">var</span> proxy = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Proxy</span>({}, {
  get: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">target, property</span>) </span>{
    <span class="hljs-keyword">return</span> <span class="hljs-number">35</span>;
  }
});

<span class="hljs-keyword">let</span> obj = <span class="hljs-built_in">Object</span>.create(proxy);

obj.time <span class="hljs-comment">// 35</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;proxy&#x5BF9;&#x8C61;&#x662F;obj&#x5BF9;&#x8C61;&#x7684;&#x539F;&#x578B;&#xFF0C;obj&#x5BF9;&#x8C61;&#x672C;&#x8EAB;&#x5E76;&#x6CA1;&#x6709;time&#x5C5E;&#x6027;&#xFF0C;&#x6240;&#x6709;&#x6839;&#x636E;&#x539F;&#x578B;&#x94FE;&#xFF0C;&#x4F1A;&#x5728;proxy&#x5BF9;&#x8C61;&#x4E0A;&#x8BFB;&#x53D6;&#x8BE5;&#x5C5E;&#x6027;&#xFF0C;&#x5BFC;&#x81F4;&#x88AB;&#x62E6;&#x622A;&#x3002;</p>
<p>&#x5BF9;&#x4E8E;&#x6CA1;&#x6709;&#x8BBE;&#x7F6E;&#x62E6;&#x622A;&#x7684;&#x64CD;&#x4F5C;&#xFF0C;&#x5219;&#x76F4;&#x63A5;&#x843D;&#x5728;&#x76EE;&#x6807;&#x51FD;&#x6570;&#x4E0A;&#xFF0C;&#x6309;&#x7167;&#x539F;&#x5148;&#x7684;&#x65B9;&#x5F0F;&#x4EA7;&#x751F;&#x7ED3;&#x679C;&#x3002;</p>
<p>&#x4E0B;&#x9762;&#x662F;&#x53E6;&#x4E00;&#x4E2A;&#x62E6;&#x622A;&#x8BFB;&#x53D6;&#x64CD;&#x4F5C;&#x7684;&#x4F8B;&#x5B50;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">var</span> person = {
  name: <span class="hljs-string">&quot;&#x5F20;&#x4E09;&quot;</span>
};

<span class="hljs-keyword">var</span> proxy = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Proxy</span>(person, {
  get: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">target, property</span>) </span>{
    <span class="hljs-keyword">if</span> (property <span class="hljs-keyword">in</span> target) {
      <span class="hljs-keyword">return</span> target[property];
    } <span class="hljs-keyword">else</span> {
      <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">ReferenceError</span>(<span class="hljs-string">&quot;Property \&quot;&quot;</span> + property + <span class="hljs-string">&quot;\&quot; does not exist.&quot;</span>);
    }
  }
});

proxy.name <span class="hljs-comment">// &quot;&#x5F20;&#x4E09;&quot;</span>
proxy.age <span class="hljs-comment">// &#x629B;&#x51FA;&#x4E00;&#x4E2A;&#x9519;&#x8BEF;</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x8868;&#x793A;&#xFF0C;&#x5982;&#x679C;&#x8BBF;&#x95EE;&#x76EE;&#x6807;&#x5BF9;&#x8C61;&#x4E0D;&#x5B58;&#x5728;&#x7684;&#x5C5E;&#x6027;&#xFF0C;&#x4F1A;&#x629B;&#x51FA;&#x4E00;&#x4E2A;&#x9519;&#x8BEF;&#x3002;&#x5982;&#x679C;&#x6CA1;&#x6709;&#x8FD9;&#x4E2A;&#x62E6;&#x622A;&#x51FD;&#x6570;&#xFF0C;&#x8BBF;&#x95EE;&#x4E0D;&#x5B58;&#x5728;&#x7684;&#x5C5E;&#x6027;&#xFF0C;&#x53EA;&#x4F1A;&#x8FD4;&#x56DE;undefined&#x3002;</p>
<p>&#x9664;&#x4E86;&#x53D6;&#x503C;&#x51FD;&#x6570;get&#xFF0C;Proxy&#x8FD8;&#x53EF;&#x4EE5;&#x8BBE;&#x7F6E;&#x5B58;&#x503C;&#x51FD;&#x6570;set&#xFF0C;&#x7528;&#x6765;&#x62E6;&#x622A;&#x67D0;&#x4E2A;&#x5C5E;&#x6027;&#x7684;&#x8D4B;&#x503C;&#x884C;&#x4E3A;&#x3002;&#x5047;&#x5B9A;Person&#x5BF9;&#x8C61;&#x6709;&#x4E00;&#x4E2A;age&#x5C5E;&#x6027;&#xFF0C;&#x8BE5;&#x5C5E;&#x6027;&#x5E94;&#x8BE5;&#x662F;&#x4E00;&#x4E2A;&#x4E0D;&#x5927;&#x4E8E;200&#x7684;&#x6574;&#x6570;&#xFF0C;&#x90A3;&#x4E48;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;Proxy&#x5BF9;&#x8C61;&#x4FDD;&#x8BC1;age&#x7684;&#x5C5E;&#x6027;&#x503C;&#x7B26;&#x5408;&#x8981;&#x6C42;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">let</span> validator = {
  set: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">obj, prop, value</span>) </span>{
    <span class="hljs-keyword">if</span> (prop === <span class="hljs-string">&apos;age&apos;</span>) {
      <span class="hljs-keyword">if</span> (!<span class="hljs-built_in">Number</span>.isInteger(value)) {
        <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">TypeError</span>(<span class="hljs-string">&apos;The age is not an integer&apos;</span>);
      }
      <span class="hljs-keyword">if</span> (value &gt; <span class="hljs-number">200</span>) {
        <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">RangeError</span>(<span class="hljs-string">&apos;The age seems invalid&apos;</span>);
      }
    }

    <span class="hljs-comment">// &#x5BF9;&#x4E8E;age&#x4EE5;&#x5916;&#x7684;&#x5C5E;&#x6027;&#xFF0C;&#x76F4;&#x63A5;&#x4FDD;&#x5B58;</span>
    obj[prop] = value;
  }
};

<span class="hljs-keyword">let</span> person = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Proxy</span>({}, validator);

person.age = <span class="hljs-number">100</span>;

person.age <span class="hljs-comment">// 100</span>
person.age = <span class="hljs-string">&apos;young&apos;</span> <span class="hljs-comment">// &#x62A5;&#x9519;</span>
person.age = <span class="hljs-number">300</span> <span class="hljs-comment">// &#x62A5;&#x9519;</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x7531;&#x4E8E;&#x8BBE;&#x7F6E;&#x4E86;&#x5B58;&#x503C;&#x51FD;&#x6570;set&#xFF0C;&#x4EFB;&#x4F55;&#x4E0D;&#x7B26;&#x5408;&#x8981;&#x6C42;&#x7684;age&#x5C5E;&#x6027;&#x8D4B;&#x503C;&#xFF0C;&#x90FD;&#x4F1A;&#x629B;&#x51FA;&#x4E00;&#x4E2A;&#x9519;&#x8BEF;&#x3002;&#x5229;&#x7528;set&#x65B9;&#x6CD5;&#xFF0C;&#x8FD8;&#x53EF;&#x4EE5;&#x6570;&#x636E;&#x7ED1;&#x5B9A;&#xFF0C;&#x5373;&#x6BCF;&#x5F53;&#x5BF9;&#x8C61;&#x53D1;&#x751F;&#x53D8;&#x5316;&#x65F6;&#xFF0C;&#x4F1A;&#x81EA;&#x52A8;&#x66F4;&#x65B0;DOM&#x3002;</p>
<p>ownKeys&#x65B9;&#x6CD5;&#x7528;&#x6765;&#x62E6;&#x622A;Object.keys()&#x64CD;&#x4F5C;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">let</span> target = {};

<span class="hljs-keyword">let</span> handler = {
  ownKeys(target) {
    <span class="hljs-keyword">return</span> [<span class="hljs-string">&apos;hello&apos;</span>, <span class="hljs-string">&apos;world&apos;</span>];
  }
};

<span class="hljs-keyword">let</span> proxy = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Proxy</span>(target, handler);

<span class="hljs-built_in">Object</span>.keys(proxy)
<span class="hljs-comment">// [ &apos;hello&apos;, &apos;world&apos; ]</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x62E6;&#x622A;&#x4E86;&#x5BF9;&#x4E8E;target&#x5BF9;&#x8C61;&#x7684;Object.keys()&#x64CD;&#x4F5C;&#xFF0C;&#x8FD4;&#x56DE;&#x9884;&#x5148;&#x8BBE;&#x5B9A;&#x7684;&#x6570;&#x7EC4;&#x3002;</p>
<p>Proxy&#x652F;&#x6301;&#x7684;&#x62E6;&#x622A;&#x64CD;&#x4F5C;&#x4E00;&#x89C8;&#x3002;</p>
<ul>
<li>defineProperty(target, propKey, propDesc)&#xFF1A;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x5E03;&#x5C14;&#x503C;&#xFF0C;&#x62E6;&#x622A;Object.defineProperty(proxy, propKey, propDesc&#xFF09;</li>
<li>deleteProperty(target, propKey) &#xFF1A;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x5E03;&#x5C14;&#x503C;&#xFF0C;&#x62E6;&#x622A;delete proxy[propKey]</li>
<li>enumerate(target)&#xFF1A;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x904D;&#x5386;&#x5668;&#xFF0C;&#x62E6;&#x622A;for (x in proxy)</li>
<li>get(target, propKey, receiver)&#xFF1A;&#x8FD4;&#x56DE;&#x7C7B;&#x578B;&#x4E0D;&#x9650;&#xFF0C;&#x62E6;&#x622A;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;&#x7684;&#x8BFB;&#x53D6;</li>
<li>getOwnPropertyDescriptor(target, propKey) &#xFF1A;&#x8FD4;&#x56DE;&#x5C5E;&#x6027;&#x7684;&#x63CF;&#x8FF0;&#x5BF9;&#x8C61;&#xFF0C;&#x62E6;&#x622A;Object.getOwnPropertyDescriptor(proxy, propKey)</li>
<li>getPrototypeOf(target) &#xFF1A;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#xFF0C;&#x62E6;&#x622A;Object.getPrototypeOf(proxy)</li>
<li>has(target, propKey)&#xFF1A;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x5E03;&#x5C14;&#x503C;&#xFF0C;&#x62E6;&#x622A;propKey in proxy</li>
<li>isExtensible(target)&#xFF1A;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x5E03;&#x5C14;&#x503C;&#xFF0C;&#x62E6;&#x622A;Object.isExtensible(proxy)</li>
<li>ownKeys(target)&#xFF1A;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x6570;&#x7EC4;&#xFF0C;&#x62E6;&#x622A;Object.getOwnPropertyPropertyNames(proxy)&#x3001;Object.getOwnPropertyPropertySymbols(proxy)&#x3001;Object.keys(proxy)</li>
<li>preventExtensions(target)&#xFF1A;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x5E03;&#x5C14;&#x503C;&#xFF0C;&#x62E6;&#x622A;Object.preventExtensions(proxy)</li>
<li>set(target, propKey, value, receiver)&#xFF1A;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x5E03;&#x5C14;&#x503C;&#xFF0C;&#x62E6;&#x622A;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;&#x7684;&#x8BBE;&#x7F6E;</li>
<li>setPrototypeOf(target, proto)&#xFF1A;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x5E03;&#x5C14;&#x503C;&#xFF0C;&#x62E6;&#x622A;Object.setPrototypeOf(proxy, proto)</li>
</ul>
<p>&#x5982;&#x679C;&#x76EE;&#x6807;&#x5BF9;&#x8C61;&#x662F;&#x51FD;&#x6570;&#xFF0C;&#x90A3;&#x4E48;&#x8FD8;&#x6709;&#x4E24;&#x79CD;&#x989D;&#x5916;&#x64CD;&#x4F5C;&#x53EF;&#x4EE5;&#x62E6;&#x622A;&#x3002;</p>
<ul>
<li>apply&#x65B9;&#x6CD5;&#xFF1A;&#x62E6;&#x622A;Proxy&#x5B9E;&#x4F8B;&#x4F5C;&#x4E3A;&#x51FD;&#x6570;&#x8C03;&#x7528;&#x7684;&#x64CD;&#x4F5C;&#xFF0C;&#x6BD4;&#x5982;proxy(&#xB7;&#xB7;&#xB7;)&#x3001;proxy.call(&#xB7;&#xB7;&#xB7;)&#x3001;proxy.apply(&#xB7;&#xB7;&#xB7;)&#x3002;</li>
<li>construct&#x65B9;&#x6CD5;&#xFF1A;&#x62E6;&#x622A;Proxy&#x5B9E;&#x4F8B;&#x4F5C;&#x4E3A;&#x6784;&#x9020;&#x51FD;&#x6570;&#x8C03;&#x7528;&#x7684;&#x64CD;&#x4F5C;&#xFF0C;&#x6BD4;&#x5982;new proxy(&#xB7;&#xB7;&#xB7;)&#x3002;</li>
</ul>
<p>Proxy.revocable&#x65B9;&#x6CD5;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x53EF;&#x53D6;&#x6D88;&#x7684;Proxy&#x5B9E;&#x4F8B;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">let</span> target = {};
<span class="hljs-keyword">let</span> handler = {};

<span class="hljs-keyword">let</span> {proxy, revoke} = <span class="hljs-built_in">Proxy</span>.revocable(target, handler);

proxy.foo = <span class="hljs-number">123</span>;
proxy.foo <span class="hljs-comment">// 123</span>

revoke();
proxy.foo <span class="hljs-comment">// TypeError: Revoked</span>
</code></pre>
<p>Proxy.revocable&#x65B9;&#x6CD5;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#xFF0C;&#x8BE5;&#x5BF9;&#x8C61;&#x7684;proxy&#x5C5E;&#x6027;&#x662F;Proxy&#x5B9E;&#x4F8B;&#xFF0C;revoke&#x5C5E;&#x6027;&#x662F;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#xFF0C;&#x53EF;&#x4EE5;&#x53D6;&#x6D88;Proxy&#x5B9E;&#x4F8B;&#x3002;&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x5F53;&#x6267;&#x884C;revoke&#x51FD;&#x6570;&#x4E4B;&#x540E;&#xFF0C;&#x518D;&#x8BBF;&#x95EE;Proxy&#x5B9E;&#x4F8B;&#xFF0C;&#x5C31;&#x4F1A;&#x629B;&#x51FA;&#x4E00;&#x4E2A;&#x9519;&#x8BEF;&#x3002;</p>
<h2 id="object-observe-%EF%BC%8Cobject-unobserve">Object.observe()&#xFF0C;Object.unobserve()</h2>
<p>Object.observe&#x65B9;&#x6CD5;&#x7528;&#x6765;&#x76D1;&#x542C;&#x5BF9;&#x8C61;&#xFF08;&#x4EE5;&#x53CA;&#x6570;&#x7EC4;&#xFF09;&#x7684;&#x53D8;&#x5316;&#x3002;&#x4E00;&#x65E6;&#x76D1;&#x542C;&#x5BF9;&#x8C61;&#x53D1;&#x751F;&#x53D8;&#x5316;&#xFF0C;&#x5C31;&#x4F1A;&#x89E6;&#x53D1;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">var</span> user = {};
<span class="hljs-built_in">Object</span>.observe(user, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">changes</span>)</span>{    
  changes.forEach(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">change</span>) </span>{
    user.fullName = user.firstName+<span class="hljs-string">&quot; &quot;</span>+user.lastName;         
  });
});

user.firstName = <span class="hljs-string">&apos;Michael&apos;</span>;
user.lastName = <span class="hljs-string">&apos;Jackson&apos;</span>;
user.fullName <span class="hljs-comment">// &apos;Michael Jackson&apos;</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;Object.observer&#x65B9;&#x6CD5;&#x76D1;&#x542C;user&#x5BF9;&#x8C61;&#x3002;&#x4E00;&#x65E6;&#x8BE5;&#x5BF9;&#x8C61;&#x53D1;&#x751F;&#x53D8;&#x5316;&#xFF0C;&#x5C31;&#x81EA;&#x52A8;&#x751F;&#x6210;fullName&#x5C5E;&#x6027;&#x3002;</p>
<p>&#x4E00;&#x822C;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;Object.observe&#x65B9;&#x6CD5;&#x63A5;&#x53D7;&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x76D1;&#x542C;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x7B2C;&#x4E8C;&#x4E2A;&#x51FD;&#x6570;&#x662F;&#x4E00;&#x4E2A;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#x3002;&#x4E00;&#x65E6;&#x76D1;&#x542C;&#x5BF9;&#x8C61;&#x53D1;&#x751F;&#x53D8;&#x5316;&#xFF08;&#x6BD4;&#x5982;&#x65B0;&#x589E;&#x6216;&#x5220;&#x9664;&#x4E00;&#x4E2A;&#x5C5E;&#x6027;&#xFF09;&#xFF0C;&#x5C31;&#x4F1A;&#x89E6;&#x53D1;&#x8FD9;&#x4E2A;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#x3002;&#x5F88;&#x660E;&#x663E;&#xFF0C;&#x5229;&#x7528;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x505A;&#x5F88;&#x591A;&#x4E8B;&#x60C5;&#xFF0C;&#x6BD4;&#x5982;&#x81EA;&#x52A8;&#x66F4;&#x65B0;DOM&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">var</span> div = $(<span class="hljs-string">&quot;#foo&quot;</span>);

<span class="hljs-built_in">Object</span>.observe(user, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">changes</span>)</span>{    
  changes.forEach(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">change</span>) </span>{
    <span class="hljs-keyword">var</span> fullName = user.firstName+<span class="hljs-string">&quot; &quot;</span>+user.lastName;         
    div.text(fullName);
  });
});
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x53EA;&#x8981;user&#x5BF9;&#x8C61;&#x53D1;&#x751F;&#x53D8;&#x5316;&#xFF0C;&#x5C31;&#x4F1A;&#x81EA;&#x52A8;&#x66F4;&#x65B0;DOM&#x3002;&#x5982;&#x679C;&#x914D;&#x5408;jQuery&#x7684;change&#x65B9;&#x6CD5;&#xFF0C;&#x5C31;&#x53EF;&#x4EE5;&#x5B9E;&#x73B0;&#x6570;&#x636E;&#x5BF9;&#x8C61;&#x4E0E;DOM&#x5BF9;&#x8C61;&#x7684;&#x53CC;&#x5411;&#x81EA;&#x52A8;&#x7ED1;&#x5B9A;&#x3002;</p>
<p>&#x56DE;&#x8C03;&#x51FD;&#x6570;&#x7684;changes&#x53C2;&#x6570;&#x662F;&#x4E00;&#x4E2A;&#x6570;&#x7EC4;&#xFF0C;&#x4EE3;&#x8868;&#x5BF9;&#x8C61;&#x53D1;&#x751F;&#x7684;&#x53D8;&#x5316;&#x3002;&#x4E0B;&#x9762;&#x662F;&#x4E00;&#x4E2A;&#x66F4;&#x5B8C;&#x6574;&#x7684;&#x4F8B;&#x5B50;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">var</span> o = {};

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">observer</span>(<span class="hljs-params">changes</span>)</span>{
    changes.forEach(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">change</span>) </span>{
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;&#x53D1;&#x751F;&#x53D8;&#x52A8;&#x7684;&#x5C5E;&#x6027;&#xFF1A;&apos;</span> + change.name);
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;&#x53D8;&#x52A8;&#x524D;&#x7684;&#x503C;&#xFF1A;&apos;</span> + change.oldValue);
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;&#x53D8;&#x52A8;&#x540E;&#x7684;&#x503C;&#xFF1A;&apos;</span> + change.object[change.name]);
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;&#x53D8;&#x52A8;&#x7C7B;&#x578B;&#xFF1A;&apos;</span> + change.type);
    });
}

<span class="hljs-built_in">Object</span>.observe(o, observer);
</code></pre>
<p>&#x53C2;&#x7167;&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#xFF0C;Object.observe&#x65B9;&#x6CD5;&#x6307;&#x5B9A;&#x7684;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#xFF0C;&#x63A5;&#x53D7;&#x4E00;&#x4E2A;&#x6570;&#x7EC4;&#xFF08;changes&#xFF09;&#x4F5C;&#x4E3A;&#x53C2;&#x6570;&#x3002;&#x8BE5;&#x6570;&#x7EC4;&#x7684;&#x6210;&#x5458;&#x4E0E;&#x5BF9;&#x8C61;&#x7684;&#x53D8;&#x5316;&#x4E00;&#x4E00;&#x5BF9;&#x5E94;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#xFF0C;&#x5BF9;&#x8C61;&#x53D1;&#x751F;&#x591A;&#x5C11;&#x4E2A;&#x53D8;&#x5316;&#xFF0C;&#x8BE5;&#x6570;&#x7EC4;&#x5C31;&#x6709;&#x591A;&#x5C11;&#x4E2A;&#x6210;&#x5458;&#x3002;&#x6BCF;&#x4E2A;&#x6210;&#x5458;&#x662F;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#xFF08;change&#xFF09;&#xFF0C;&#x5B83;&#x7684;name&#x5C5E;&#x6027;&#x8868;&#x793A;&#x53D1;&#x751F;&#x53D8;&#x5316;&#x6E90;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#x540D;&#xFF0C;oldValue&#x5C5E;&#x6027;&#x8868;&#x793A;&#x53D1;&#x751F;&#x53D8;&#x5316;&#x524D;&#x7684;&#x503C;&#xFF0C;object&#x5C5E;&#x6027;&#x6307;&#x5411;&#x53D8;&#x52A8;&#x540E;&#x7684;&#x6E90;&#x5BF9;&#x8C61;&#xFF0C;type&#x5C5E;&#x6027;&#x8868;&#x793A;&#x53D8;&#x5316;&#x7684;&#x79CD;&#x7C7B;&#x3002;&#x57FA;&#x672C;&#x4E0A;&#xFF0C;change&#x5BF9;&#x8C61;&#x662F;&#x4E0B;&#x9762;&#x7684;&#x6837;&#x5B50;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">var</span> change = {
  object: {...}, 
  type: <span class="hljs-string">&apos;update&apos;</span>, 
  name: <span class="hljs-string">&apos;p2&apos;</span>, 
  oldValue: <span class="hljs-string">&apos;Property 2&apos;</span>
}
</code></pre>
<p>Object.observe&#x65B9;&#x6CD5;&#x76EE;&#x524D;&#x5171;&#x652F;&#x6301;&#x76D1;&#x542C;&#x516D;&#x79CD;&#x53D8;&#x5316;&#x3002;</p>
<ul>
<li>add&#xFF1A;&#x6DFB;&#x52A0;&#x5C5E;&#x6027;</li>
<li>update&#xFF1A;&#x5C5E;&#x6027;&#x503C;&#x7684;&#x53D8;&#x5316;</li>
<li>delete&#xFF1A;&#x5220;&#x9664;&#x5C5E;&#x6027;</li>
<li>setPrototype&#xFF1A;&#x8BBE;&#x7F6E;&#x539F;&#x578B;</li>
<li>reconfigure&#xFF1A;&#x5C5E;&#x6027;&#x7684;attributes&#x5BF9;&#x8C61;&#x53D1;&#x751F;&#x53D8;&#x5316;</li>
<li>preventExtensions&#xFF1A;&#x5BF9;&#x8C61;&#x88AB;&#x7981;&#x6B62;&#x6269;&#x5C55;&#xFF08;&#x5F53;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x53D8;&#x5F97;&#x4E0D;&#x53EF;&#x6269;&#x5C55;&#x65F6;&#xFF0C;&#x4E5F;&#x5C31;&#x4E0D;&#x5FC5;&#x518D;&#x76D1;&#x542C;&#x4E86;&#xFF09;</li>
</ul>
<p>Object.observe&#x65B9;&#x6CD5;&#x8FD8;&#x53EF;&#x4EE5;&#x63A5;&#x53D7;&#x7B2C;&#x4E09;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x7528;&#x6765;&#x6307;&#x5B9A;&#x76D1;&#x542C;&#x7684;&#x4E8B;&#x4EF6;&#x79CD;&#x7C7B;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-built_in">Object</span>.observe(o, observer, [<span class="hljs-string">&apos;delete&apos;</span>]);
</code></pre>
<p>&#x4E0A;&#x9762;&#x7684;&#x4EE3;&#x7801;&#x8868;&#x793A;&#xFF0C;&#x53EA;&#x5728;&#x53D1;&#x751F;delete&#x4E8B;&#x4EF6;&#x65F6;&#xFF0C;&#x624D;&#x4F1A;&#x8C03;&#x7528;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#x3002;</p>
<p>Object.unobserve&#x65B9;&#x6CD5;&#x7528;&#x6765;&#x53D6;&#x6D88;&#x76D1;&#x542C;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-built_in">Object</span>.unobserve(o, observer);
</code></pre>
<p>&#x6CE8;&#x610F;&#xFF0C;Object.observe&#x548C;Object.unobserve&#x8FD9;&#x4E24;&#x4E2A;&#x65B9;&#x6CD5;&#x4E0D;&#x5C5E;&#x4E8E;ES6&#xFF0C;&#x800C;&#x662F;&#x5C5E;&#x4E8E;ES7&#x7684;&#x4E00;&#x90E8;&#x5206;&#x3002;&#x4E0D;&#x8FC7;&#xFF0C;Chrome&#x6D4F;&#x89C8;&#x5668;&#x4ECE;33&#x7248;&#x8D77;&#x5C31;&#x5DF2;&#x7ECF;&#x652F;&#x6301;&#x3002;</p>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="array.html" class="navigation navigation-prev " aria-label="Previous page: &#x6570;&#x7EC4;&#x7684;&#x6269;&#x5C55;"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="function.html" class="navigation navigation-next " aria-label="Next page: &#x51FD;&#x6570;&#x7684;&#x6269;&#x5C55;"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="static/js/app.js"></script>

    
    <script src="static/js/plugin.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"fontSettings":{"theme":null,"family":"sans","size":2},"disqus":{"shortName":"git-book"}};
    gitbook.start(config);
});
</script>

        
    
    

</body></html>